package com.tjetc.dao.impl;

import com.tjetc.dao.ExcelDao;
import com.tjetc.pojo.entity.Income;
import com.tjetc.pojo.vo.CountVO;
import com.tjetc.utils.DruidUtils;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: itda
 * @Date: 2024/5/11 22:04
 * @Description: ExcelDaoImpl
 */
public class ExcelDaoImpl implements ExcelDao {
    @Override
    public List<Income> getCostByTime(LocalDateTime start, LocalDateTime end) throws Exception {
        return DruidUtils.r2.query("select * from income where create_time between ? and ?", new BeanListHandler<>(Income.class, DruidUtils.rowProcessor), start, end);
    }

    @Override
    public List<CountVO> getCountCostByTime(LocalDateTime now) throws Exception{
        return DruidUtils.r2.query("select h.id,count(i.cost) from income i,hotel h,room r where i.room_id = r.id and r.hotel_id = h.id and i.create_time < ? group by h.id"
                ,new BeanListHandler<>(CountVO.class),now);
    }
}
